home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
gui
/
gtlayout.lha
/
Source
/
LTP_PopupClass.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-09
|
26KB
|
1,285 lines
/*
** GadTools layout toolkit
**
** Copyright © 1993-1998 by Olaf `Olsen' Barthel
** Freely distributable.
**
** :ts=4
*/
#ifndef _GTLAYOUT_GLOBAL_H
#include "gtlayout_global.h"
#endif
/*****************************************************************************/
#include <intuition/classes.h>
#include <clib/alib_protos.h> /* For Coerce/Do/DoSuperMethod */
/*****************************************************************************/
#include "Assert.h"
/*****************************************************************************/
#ifdef DO_POPUP_KIND /* Support code */
#define PIF_SingleActive (1 << 0)
#define PIF_ArrowUp (1 << 1)
#define PIF_ArrowDown (1 << 2)
STATIC VOID
DrawArrow(
struct RastPort * RPort,
LONG Left,
LONG Top,
LONG ArrowWidth,
LONG ArrowHeight,
LONG Dir)
{
LONG i,Width,Start,Pos;
for(i = 0 ; i < ArrowHeight ; i++)
{
Width = ((ArrowWidth * (i + 1)) / ArrowHeight) & ~1;
if(Width < ArrowWidth)
Width++;
Start = Left + (ArrowWidth - Width) / 2;
if(Dir < 0)
Pos = Top + i;
else
Pos = Top + ArrowHeight - 1 - i;
LTP_DrawLine(RPort,Start,Pos,Start + Width - 1,Pos);
}
}
STATIC VOID
DrawContainer(
struct RastPort * RPort,
LONG Left,
LONG Top,
LONG Width,
LONG Height,
struct GadgetInfo * GadgetInfo,
PopInfo * Info,
UWORD Highlight,
UWORD Disabled)
{
LONG Shine,Shadow,Txt,Fill;
LONG Right;
UWORD * Pens;
Pens = GadgetInfo->gi_DrInfo->dri_Pens;
if(Highlight)
{
Shine = Pens[SHADOWPEN];
Shadow = Pens[SHINEPEN];
Txt = Pens[FILLTEXTPEN];
Fill = Pens[FILLPEN];
}
else
{
Shine = Pens[SHINEPEN];
Shadow = Pens[SHADOWPEN];
Txt = Pens[TEXTPEN];
Fill = Pens[BACKGROUNDPEN];
}
LTP_SetPens(RPort,Fill,0,JAM1);
if(Info->FrameImage != NULL)
{
DrawImageState(RPort,Info->FrameImage,Left,Top,Highlight ? IDS_SELECTED : IDS_NORMAL,GadgetInfo->gi_DrInfo);
}
else
{
LTP_FillBox(RPort,Left + 2,Top + 1,Width - 4,Height - 2);
LTP_RenderBevel(RPort,Pens,Left,Top,Width,Height,Highlight,2);
}
Right = Left + Width - Info->MarkLeft;
LTP_SetAPen(RPort,Shadow);
LTP_DrawLine(RPort,Right,Top + 2,Right,Top + Height - 3);
LTP_SetAPen(RPort,Shine);
LTP_DrawLine(RPort,Right + 1,Top + 2,Right + 1,Top + Height - 3);
SetFont(RPort,Info->Font);
LTP_SetAPen(RPort,Txt);
LTP_DrawAdjustedPicker(RPort,FALSE,Right + 2,Top,Info->PickerWidth,Height,Info->AspectX,Info->AspectY);
LTP_PrintText(RPort,Info->Labels[Info->Active],Info->ActiveLen,Left + 6,Top + Info->LabelTop);
if(Disabled)
LTP_GhostBox(RPort,Left,Top,Width,Height,Pens[SHADOWPEN]);
}
STATIC VOID
DrawOneBox(
PopInfo * Info,
LONG Top,
LONG Index)
{
struct RastPort * RPort;
LONG Len;
LONG Extra;
STRPTR Label;
Label = Info->Labels[Index];
RPort = Info->Window->RPort;
if((Len = strlen(Label)) > Info->MaxLen)
Len = Info->MaxLen;
if(Info->CheckGlyph)
Extra = Info->CheckGlyph->Width + 2;
else
Extra = 0;
LTP_PrintText(RPort,Label,Len,6 + Extra,Top + Info->LineTop);
if(Extra && Index == Info->InitialActive)
LTP_DrawCheckGlyph(RPort,6,Top + Info->LineTop,Info->CheckGlyph,Index == Info->LastLabelDrawn);
}
STATIC VOID
DrawOneGlyph(
PopInfo * Info,
LONG Top,
LONG Dir,
UWORD * Pens)
{
struct RastPort *RPort;
RPort = Info->Window->RPort;
if(Pens != NULL)
{
LTP_SetAPen(RPort,Info->MenuBack);
LTP_FillBox(RPort,4,Top,Info->SingleWidth,Info->SingleHeight);
LTP_SetAPen(RPort,Info->MenuText);
}
DrawArrow(RPort,6,Top + Info->ArrowTop,Info->ArrowWidth,Info->ArrowHeight,Dir);
}
STATIC VOID
BoxRender(
PopInfo * Info,
UWORD * Pens,
LONG Active,
BOOL FullRefresh,
BOOL Highlight,
LONG Dir)
{
struct RastPort *RPort = Info->Window->RPort;
if(FullRefresh)
{
LONG Index,Top;
LONG Width,Height;
LTP_SetPens(RPort,Info->MenuBack,0,JAM1);
Width = Info->Window->Width;
Height = Info->Window->Height;
LTP_FillBox(RPort,2,1,Width - 4,Height - 2);
LTP_SetAPen(RPort,Info->MenuText);
LTP_PolyDraw(RPort,5,
1,1,
1,Height - 2,
0,Height - 2,
0,0,
Width - 1,0);
LTP_PolyDraw(RPort,5,
0,Height - 1,
Width - 1,Height - 1,
Width - 1,1,
Width - 2,1,
Width - 2,Height - 2);
Index = Info->TopMost;
Top = 2;
Height = Info->BoxHeight;
Info->Flags &= ~(PIF_ArrowUp | PIF_ArrowDown);
if(Info->TopMost > 0 && Active != Info->TopMost && Info->BoxLines > 2)
{
Info->Flags |= PIF_ArrowUp;
Index += 1;
Top += Info->SingleHeight;
Height -= Info->SingleHeight;
}
if(Info->TopMost + Info->BoxLines < Info->NumLabels && Active != Info->TopMost + Info->BoxLines - 1 && Info->BoxLines > 2)
{
Info->Flags |= PIF_ArrowDown;
Height -= Info->SingleHeight;
}
Info->LastLabelDrawn = Active; // IMPORTANT: must be set up here to DrawOneBox can find it
for(NULL ; Index < Info->NumLabels && Height > 0 ; Index++, Top += Info->SingleHeight, Height -= Info->SingleHeight)
{
if(Index == Active)
{
LTP_SetAPen(RPort,Info->MenuBackSelect);
LTP_FillBox(RPort,4,Top,Info->SingleWidth,Info->SingleHeight);
LTP_SetAPen(RPort,Info->MenuTextSelect);
DrawOneBox(Info,Top,Index);
LTP_SetAPen(RPort,Info->MenuText);
}
else
{
DrawOneBox(Info,Top,Index);
}
}
if(Info->Flags & PIF_ArrowUp)
DrawOneGlyph(Info,2,-1,NULL);
if(Info->Flags & PIF_ArrowDown)
DrawOneGlyph(Info,2 + (Info->BoxLines - 1) * Info->SingleHeight,1,NULL);
Info->LastDrawn = 2 + (Active - Info->TopMost) * Info->SingleHeight;
}
else
{
if(Info->LastLabelDrawn != -1)
{
LONG Top = Info->LastDrawn,Last = Info->LastLabelDrawn;
Info->LastLabelDrawn = -1;
LTP_SetPens(RPort,Info->MenuBack,0,JAM1);
LTP_FillBox(RPort,4,Top,Info->SingleWidth,Info->SingleHeight);
LTP_SetAPen(RPort,Info->MenuText);
DrawOneBox(Info,Top,Last);
}
Info->LastDrawn = -1;
if(Active >= 0)
{
LONG Top,NewActive;
NewActive = Active - Info->TopMost;
Top = 2 + NewActive * Info->SingleHeight;
if(Top >= 2 && Top < Info->BoxHeight + 2)
{
LONG Pen;
if(Dir != 0)
Highlight = FALSE;
if(Highlight)
{
Pen = Info->MenuBackSelect;
Info->LastDrawn = Top;
Info->LastLabelDrawn = Active;
}
else
{
Pen = Info->MenuBack;
}
LTP_SetPens(RPort,Pen,0,JAM1);
LTP_FillBox(RPort,4,Top,Info->SingleWidth,Info->SingleHeight);
if(Highlight)
Pen = Info->MenuTextSelect;
else
Pen = Info->MenuText;
LTP_SetAPen(RPort,Pen);
if(Dir == 0)
DrawOneBox(Info,Top,Active);
else
DrawOneGlyph(Info,Top,Dir,NULL);
}
}
}
}
STATIC ULONG
InputMethod(
struct IClass * class,
struct Gadget * gadget,
struct gpInput * InputInfo)
{
PopInfo *Info = INST_DATA(class,gadget);
ULONG Result = GMR_MEACTIVE;
BOOL Done = FALSE;
BOOL Redraw = FALSE;
if(InputInfo->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE)
{
UWORD Code = InputInfo->gpi_IEvent->ie_Code;
if(Code == MENUDOWN)
{
Result = GMR_NOREUSE;
Done = TRUE;
Info->Active = Info->InitialActive;
}
else
{
if(Code == SELECTUP)
{
Done = TRUE;
if(Info->Active < 0)
{
Result = GMR_NOREUSE;
Info->Active = Info->InitialActive;
}
else
{
LONG Len;
Result = GMR_NOREUSE | GMR_VERIFY;
if(Info->Flags & PIF_SingleActive)
{
LONG Width,Height;
LONG x,y;
x = InputInfo->gpi_Mouse.X;
y = InputInfo->gpi_Mouse.Y;
Width = gadget->Width;
Height = gadget->Height;
if(x >= 0 && y >= 0 && x < Width && y < Height)
{
if(InputInfo->gpi_IEvent->ie_Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
Info->Active--;
else
Info->Active++;
if(Info->Active >= Info->NumLabels)
{
Info->Active = 0;
}
else
{
if(Info->Active < 0)
Info->Active = Info->NumLabels - 1;
}
}
else
{
Result = GMR_NOREUSE;
Info->Active = Info->InitialActive;
}
}
Len = strlen(Info->Labels[Info->Active]);
if(Len > Info->MaxLen)
Len = Info->MaxLen;
Info->ActiveLen = Len;
(*InputInfo->gpi_Termination) = Info->Active;